Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
46.15% covered (warning)
46.15%
6 / 13
CRAP
73.21% covered (warning)
73.21%
41 / 56
SWIFT_Base
0.00% covered (danger)
0.00%
0 / 1
46.15% covered (warning)
46.15%
6 / 13
60.91
73.21% covered (warning)
73.21%
41 / 56
 __construct
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
3 / 3
 __destruct
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 ProcessInstanceID
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 GetInstanceID
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 Initialize
0.00% covered (danger)
0.00%
0 / 1
11.02
94.74% covered (success)
94.74%
18 / 19
 OverrideObjects
0.00% covered (danger)
0.00%
0 / 1
56.00
0.00% covered (danger)
0.00%
0 / 7
 UpdateObject
0.00% covered (danger)
0.00%
0 / 1
4.37
71.43% covered (warning)
71.43%
5 / 7
 SetIsClassLoaded
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 GetIsClassLoaded
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 GetErrorMessage
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 1
 GetErrorMessageArray
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 1
 GetErrorNumber
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 1
 Log
0.00% covered (danger)
0.00%
0 / 1
5.20
80.00% covered (success)
80.00%
8 / 10
<?php
/**
 * ###############################################
 *
 * SWIFT Framework
 * _______________________________________________
 *
 * @author         Varun Shoor
 *
 * @package        SWIFT
 * @copyright      Copyright (c) 2001-2012, Kayako
 * @license        http://www.kayako.com/license
 * @link           http://www.kayako.com
 *
 * ###############################################
 */
use Base\Library\UserInterface\SWIFT_UserInterface;
use Base\Library\UserInterface\SWIFT_UserInterfaceClient;
use Base\Library\UserInterface\SWIFT_UserInterfaceControlPanel;
/**
 * The SWIFT Base Class
 *
 * @author Varun Shoor
 */
abstract class SWIFT_Base
{
    protected $_errorMsg = array();
    protected $_classLoaded = false;
    protected $_clusterBaseDirectory;
    // Protected Objects
    /**
     * @var SWIFT_Database|false
     */
    protected $Database = false;
    /**
     * @var SWIFT_Registry|false
     */
    protected $Registry = false;
    /**
     * @var SWIFT_Interface|false
     */
    protected $Interface = false;
    /**
     * @var SWIFT_App|false
     */
    protected $App = false;
    /**
     * @var SWIFT_LanguageEngine|false
     */
    protected $Language = false;
    /**
     * @var SWIFT_TemplateEngine|false
     */
    protected $Template = false;
    /**
     * @var SWIFT_Session|false
     */
    protected $Session = false;
    /**
     * @var SWIFT_Settings|false
     */
    protected $Settings = false;
    /**
     * @var SWIFT_CacheStore|false
     */
    protected $Cache = false;
    /**
     * @var SWIFT_Router|false
     */
    protected $Router = false;
    /**
     * @var SWIFT_View|false
     */
    protected $View = false;
    /**
     * @var SWIFT_Cookie|false
     */
    protected $Cookie = false;
    /**
     * @var SWIFT_Console|false
     */
    protected $Console = false;
    /**
     * @var SWIFT_Log|false
     */
    protected $Log = false;
    /**
     * @var SWIFT_System|false
     */
    protected $System = false;
    /**
     * @var SWIFT_Controller|false
     */
    protected $Controller = false;
    /**
     * @var SWIFT_UserInterface|SWIFT_UserInterfaceControlPanel|false
     */
    protected $UserInterface = false;
    /**
     * @var SWIFT_Hook|false
     */
    protected $Hook = false;
    // Non Core Protected Objects
    /**
     * @var SWIFT_Library|false
     */
    public $Server = false;
    /**
     * @var SWIFT_Library|false
     */
    public $ServerMaster = false;
    /**
     * @var SWIFT_Library|false
     */
    public $Cluster = false;
    /**
     * @var SWIFT_JobQueueMessageRemote|false
     */
    protected $JobQueueMessage = false;
    /**
     * @var SWIFT_DynectSession|false
     */
    protected $DynectSession = false;
    /**
     * @var SWIFT_JavaScript|false
     */
    protected $JavaScript = false;
    /**
     * @var SWIFT_Emoji|false
     */
    protected $Emoji = false;
   /**
    * @var SWIFT_Loader|false
    */
    public $Load = false;
    /**
     * @var SWIFT_Input|false
    */
    public $Input = false;
    protected $_instanceID = false;
    static private $_instanceCount = 0;
    // Core Constants
    const CLASS_PREFIX = 'SWIFT_';
    /**
     * Constructor
     *
     * @author Varun Shoor
     */
    protected function __construct()
    {
        $this->SetIsClassLoaded(true);
        $this->ProcessInstanceID();
    }
    /**
     * The Generic Destructor
     *
     * @author Varun Shoore
     */
    public function __destruct()
    {    }
    /**
     * Process the instance id for this object
     *
     * @author Varun Shoor
     * @return bool "true" on Success, "false" otherwise
     */
    private function ProcessInstanceID()
    {
        $this->_instanceID = ++self::$_instanceCount;
        return true;
    }
    /**
     * Retrieve the Instance ID for this object
     *
     * @author Varun Shoor
     * @return int The Instance ID
     */
    public function GetInstanceID()
    {
        return $this->_instanceID;
    }
    /**
     * Initialize this Model
     *
     * @author Varun Shoor
     * @return bool "true" on Success, "false" otherwise
     */
    protected function Initialize()
    {
        $_SWIFT = SWIFT::GetInstance();
        $_classInitializationList = array(
            'Database'        => 'SWIFT_Database',
            'Registry'        => 'SWIFT_Registry',
            'Interface'       => 'SWIFT_Interface',
            'App'             => 'SWIFT_App',
            'Language'        => 'SWIFT_LanguageEngine',
            'Template'        => 'SWIFT_TemplateEngine',
            'Session'         => 'SWIFT_Session',
            'Settings'        => 'SWIFT_Settings',
            'Console'         => 'SWIFT_Console',
            'System'          => 'SWIFT_System',
            'Cache'           => 'SWIFT_CacheStore',
            'Router'          => 'SWIFT_Router',
            'Cookie'          => 'SWIFT_Cookie',
            'Hook'            => 'SWIFT_Hook',
            'Log'             => 'SWIFT_Log',
            'UserInterface'   => 'Base\Library\UserInterface\SWIFT_UserInterface',
            'FirePHP'         => 'SWIFT_FirePHP',
            'JavaScript'      => 'SWIFT_JavaScript',
            'Input'           => 'SWIFT_Input',
            'Emoji'           => 'SWIFT_Emoji',
            // Non Core
            'Server'          => 'SWIFT_Server',
            'ServerMaster'    => 'SWIFT_Server',
            'JobQueueMessage' => 'SWIFT_JobQueueMessage'
        );
        foreach ($_classInitializationList as $_key => $_val) {
            if (!isset($_SWIFT->{$_key})) {
                continue;
            }
            $_objectReference = $_SWIFT->{$_key};
            if ($_objectReference instanceof SWIFT_Base) {
                if (get_class($_objectReference) == $_val && $_objectReference->GetIsClassLoaded()) {
                    $this->$_key = $_objectReference;
                } else {
                    $this->$_key = &$_SWIFT->$_key;
                }
            }
        }
        $this->Load = new SWIFT_Loader($this);
        foreach (SWIFT::GetObjectMap() as $_SWIFT_BaseObject) {
            if ($_SWIFT_BaseObject instanceof SWIFT_Base && $_SWIFT_BaseObject->GetisClassLoaded()) {
                $_className = get_short_class($_SWIFT_BaseObject);
                $_chunkClassName = substr($_className, strlen('SWIFT_'));
                if (isset($this->$_chunkClassName) && is_object($this->$_chunkClassName)) {
                    continue;
                }
                $this->$_chunkClassName = $_SWIFT_BaseObject;
            }
        }
        return true;
    }
    /**
     * Overrides the global objects for this class
     *
     * @author Varun Shoor
     *
     * @param SWIFT_Interface $_SWIFT_InterfaceObject The SWIFT_Interface Object Pointer
     * @param SWIFT_App       $_SWIFT_AppObject       The SWIFT_App Object Pointer
     * @param SWIFT_Router    $_SWIFT_RouterObject    The SWIFT_Router Object Pointer
     *
     * @return bool "true" on Success, "false" otherwise
     */
    protected function OverrideObjects(
        SWIFT_Interface $_SWIFT_InterfaceObject, SWIFT_App $_SWIFT_AppObject, SWIFT_Router $_SWIFT_RouterObject)
    {
        if ($_SWIFT_InterfaceObject instanceof SWIFT_Interface && $_SWIFT_InterfaceObject->GetIsClassLoaded()) {
            $this->Interface = $_SWIFT_InterfaceObject;
        }
        if ($_SWIFT_AppObject instanceof SWIFT_App && $_SWIFT_AppObject->GetIsClassLoaded()) {
            $this->App = $_SWIFT_AppObject;
        }
        if ($_SWIFT_RouterObject instanceof SWIFT_Router && $_SWIFT_RouterObject->GetIsClassLoaded()) {
            $this->Router = $_SWIFT_RouterObject;
        }
        return true;
    }
    /**
     * Updates the object instances in this class
     *
     * @author Varun Shoor
     *
     * @param string $_objectName    The Object Name
     * @param object $_objectPointer The Object Pointer
     *
     * @return bool "true" on Success, "false" otherwise
     */
    public function UpdateObject($_objectName, $_objectPointer)
    {
        $_objectName = Clean($_objectName);
        if (empty($_objectName)) {
            return false;
        }
        if ($_objectPointer instanceof SWIFT_Base && $_objectPointer->GetIsClassLoaded()) {
            $this->$_objectName = $_objectPointer;
            return true;
        }
        return false;
    }
    /**
     * Return the error message if any
     *
     * @author Varun Shoor
     *
     * @param bool    $_classLoaded
     *
     * @return bool
     */
    public function SetIsClassLoaded($_classLoaded)
    {
        $this->_classLoaded = $_classLoaded;
        return $_classLoaded;
    }
    /**
     * Return the error message if any
     *
     * @author Varun Shoor
     * @return bool
     */
    public function GetIsClassLoaded()
    {
        return $this->_classLoaded;
    }
    /**
     * Return the error message if any
     *
     * @author Varun Shoor
     * @return bool
     */
    public function GetErrorMessage()
    {
        return $this->_errorMsg[(count($this->_errorMsg) - 1)][0];
    }
    /**
     * Return the complete error message array
     *
     * @author Varun Shoor
     * @return bool
     */
    public function GetErrorMessageArray()
    {
        return $this->_errorMsg;
    }
    /**
     * Return the error number if any
     *
     * @author Varun Shoor
     * @return bool
     */
    public function GetErrorNumber()
    {
        return $this->_errorMsg[(count($this->_errorMsg) - 1)][1];
    }
    /**
     * Run SWIFT_Log::Log
     *
     * @author Varun Shoor
     *
     * @param string   $_logMessage    The message to write
     * @param int|bool     $_messageType   (OPTIONAL) The Message Type
     * @param string   $_messagePrefix (OPTIONAL) The Message Prefix
     *
     * @return bool "true" on Success, "false" otherwise
     * @throws SWIFT_Exception If the Class is not Loaded
     */
    public function Log($_logMessage, $_messageType = false, $_messagePrefix = '')
    {
        if (!$this->GetIsClassLoaded()) {
            throw new SWIFT_Exception(__CLASS__ . ':  ' . SWIFT_CLASSNOTLOADED);
        } else {
            if (!$this->Log instanceof SWIFT_Log) {
                return false;
            }
        }
        if (empty($_messagePrefix)) {
            $_messagePrefix = get_short_class($this);
        }
        if (empty($_messageType)) {
            $_messageType = SWIFT_Log::TYPE_NONE;
        }
        $this->Log->Log($_logMessage, $_messageType, $_messagePrefix);
        return true;
    }
}
?>